//
//  SCBasicTableViewController.swift
//  weibo
//
//  Created by 阿城 on 15/12/6.
//  Copyright © 2015年 阿城. All rights reserved.
//

import UIKit

class SCBasicTableViewController: UITableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        login ? super.loadView() : setupUI()

    }

    
    var login: Bool {
        return SCUserInfoViewModel.shareInfoViewModel.isLogOn
    }
    
    var visitorView :SCVisitorView?
    

//
//    override func viewWillAppear(animated: Bool){
//        super.viewWillAppear(animated)
////        printLog("viewWillAppear---", SCUserInfoViewModel.shareInfoViewModel.userInfoMod )
//        !login ? setupUI() : {self.loadView()
//            visitorView = nil
//            navigationItem.leftBarButtonItem = nil
//            navigationItem.rightBarButtonItem = nil
//            }()
//    }
    
    private func setupUI(){
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: "customLogin")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: "customRegister")
        
        visitorView = SCVisitorView()
        view = visitorView
//        view = SCVisitorView()
//        printLog(view.frame)
        
        visitorView?.loginClosrue = {
            self.customLogin()
        }
        
        visitorView?.registerClosrue = {
            self.customRegister()
        }
        
    }

    
    @objc private func customLogin(){
        printLog("cutomLogin")
        let webVc = SCWebViewController()
        presentViewController(UINavigationController(rootViewController: webVc), animated: true, completion: nil)
    }
    @objc private func customRegister(){
        printLog("customRegister")
    }
    
    
    func demo(){
        
//        view.addSubview(circle)
//        view.addSubview(mask)
//        view.addSubview(home)
//        
//        //home
//        home.translatesAutoresizingMaskIntoConstraints = false
//        view.addConstraint(NSLayoutConstraint(item: home, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 0))
//        view.addConstraint(NSLayoutConstraint(item: home, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: 0))
//        
//        //circle
//        circle.translatesAutoresizingMaskIntoConstraints = false
//        view.addConstraint(NSLayoutConstraint(item: circle, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 0))
//        view.addConstraint(NSLayoutConstraint(item: circle, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: 0))
//        
//        //mask
//        mask.translatesAutoresizingMaskIntoConstraints = false
//        view.addConstraint(NSLayoutConstraint(item: mask, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: 0))
//        view.addConstraint(NSLayoutConstraint(item: mask, attribute: NSLayoutAttribute.Right, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.Right, multiplier: 1, constant: 0))
//        view.addConstraint(NSLayoutConstraint(item: mask, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.Left, multiplier: 1, constant: 0))
//        view.addConstraint(NSLayoutConstraint(item: mask, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: home, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 110))
    }
    
    
    // MARK: - Table view data source





}
